* In-text numbers in the Calibration subsection
* 12 Jun 2020

clear all
set more off

*  Main calibration
use "$intermediate/data_for_matlab_stups_all.dta" , clear

label define cases 1 "l>0, h>0, h'>0" 2 "l>0, h>0, h'=0" 3 "l>0, h=0, h'>0" 4 "l>0, h=0, h'=0" 5 "l=0, h>0, h'>0" 6 "l=0, h>0, h'=0" 7 "l=0, h=0"
label values case1 cases
label values case2 cases

log using "$output/calibration.log", replace
tab case1 case2, cell nofreq

preserve
keep hhid3 pAssets1 case1 case2
gen identified = 0
replace identified = 1 if (case2 == 1) | (case2 == 2 & case1 >= 6) | (case2 == 3 & case1 >= 6)
summarize pAssets1, detail
keep if inrange(pAssets1, r(p5), r(p95))

twoway (histogram pAssets1 if identified==1, color(green)) ///
       (histogram pAssets1 if identified==0, ///
	   fcolor(none) lcolor(black)), legend(order(1 "Parameters identified" 2 "Parameters not identified" ))
restore

log close


* Calibration using waves 2&3, 3&4, 4&5
forv j = 3/5 {
	local i = `j' - 1
	use "$intermediate/data_calib_w`j'_all.dta", clear
	label define cases 1 "l>0 h>0 h'>0" 2 "l>0 h>0 h'=0" 3 "l>0 h=0 h'>0" 4 "l>0 h=0 h'=0" 5 "l=0 h>0 h'>0" 6 "l=0 h>0 h'=0" 7 "l=0 h=0"
	label values case`i' cases
	label values case`j' cases
	
	estpost tabulate case`i' case`j'
	esttab using "$output/w`j'calibration.csv", cell(pct) unstack noobs replace
}